//package com.pxd.fliter;
//
//import jakarta.servlet.*;
//import jakarta.servlet.annotation.WebFilter;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.io.IOException;
//
/**
 * 进行过滤器操作
 */

//@Component
//@WebFilter(urlPatterns = "/vido/123456.mp4")
//public class CountFilteree implements Filter {
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//        //进行过滤器的初始化
//        ServletContext context = filterConfig.getServletContext();
//        context.setAttribute("count", 0);
//    }
//
//    @Override
//    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//        //对过滤器的核心业务进行编写
//        ServletContext context = request.getServletContext();
//        Integer count = (Integer) context.getAttribute("count");
//        context.setAttribute("count", ++count);
//        chain.doFilter(request, response);
//    }
//
//    @Override
//    public void destroy() {
//        //对过滤器进行销毁
//        System.out.println("过滤器已经销毁");
//        Filter.super.destroy();
//    }
//}
//
//@RestController
//class countcontroller {
//    @GetMapping("/vido/123456.mp4")
//    public String index(HttpServletRequest request) {
//        ServletContext context = request.getServletContext();
//        Integer count = (Integer) context.getAttribute("count");
//        System.out.println(count);
//        if (count < 10) {
//            return count + "次访问";
//        }
//        return "说明已经访问10次";
//    }
//}
